import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/net/net_response/menu/regular_menu_data.dart';
import 'package:saas_order_meal/ui/regular_menu_contain_widget.dart';
import 'package:saas_order_meal/viewmodel/week_menu_choose_view_model.dart';

import '../model/order_request_data.dart';

class WeekMenuChoosePage extends BaseStatefulMvvmWidget {

  final OrderRequestData orderData;

  WeekMenuChoosePage(
      {required this.orderData,});

  @override
  State<StatefulWidget> createState() => _WeekMenuChooseState();
}

class _WeekMenuChooseState
    extends BaseMvvmState<WeekMenuChooseViewModel, WeekMenuChoosePage> {
  @override
  Widget? buildLoadingContentView() {
    if(viewModel.menuData==null){
      return Container();
    }
    var type = viewModel.menuData!["type"];
    var list = viewModel.menuData!["menuList"] as List;

    if(type.toString()=="1"){
      ///常规
      var menu = list.map((e) => RegularMenuData.fromJson(e)).toList();
      return RegularMenuContainWidget(menuList: menu,orderData: widget.orderData,isRegular: true,);
    }

    if(type.toString()=="2"){
      ///AB
      return Container();
    }
    if(type.toString()=="3"){
      ///几选几
      var menu = list.map((e) => RegularMenuData.fromJson(e)).toList();
      return RegularMenuContainWidget(menuList: menu,orderData: widget.orderData,isRegular: false,);
    }

    if(type.toString()=="4"){
      ///几选几
      var menu = list.map((e) => RegularMenuData.fromJson(e)).toList();
      return RegularMenuContainWidget(menuList: menu,orderData: widget.orderData,isRegular: true,);
    }

    return Container();
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text("${widget.orderData.elderName}-${widget.orderData.date}菜单"),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  WeekMenuChooseViewModel createViewModel() {
    return WeekMenuChooseViewModel(context,
        orderData: widget.orderData);
  }

  @override
  void onRetryClick() {
    viewModel.getWeekMenu();
  }
}
